package com.baseframe.advert.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baseframe.advert.entity.SnsAdvert;
import com.baseframe.advert.entity.request.SnsAdvertRequest;
import com.baseframe.advert.entity.vo.SnsAdvertVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * 数据库操作Mapper，用于对【sns_advert(广告表)】表进行操作
 *
 * @Entity com.baseframe.advert.entity.SnsAdvert
 */
public interface SnsAdvertMapper extends BaseMapper<SnsAdvert> {

    /**
     * 分页查询广告信息
     *
     * @param page    分页对象
     * @param request 请求对象，包含查询条件
     * @return 返回广告信息的分页结果
     */
    @Select("<script>" +
            "select sa.*,bu.username from sns_advert as sa left join base_user as bu on sa.publisher = bu.id" +
            "<where>" +
            "sa.is_deleted = 0 " +
            "<if test=\" request.slogan!=null &amp;&amp; request.slogan !='' \">" +
            "and sa.slogan like concat('%',#{request.slogan},'%')" +
            "</if>" +
            "</where>" +
            "order by sa.create_time desc" +
            "</script>")
    @Results(@Result(column = "username", property = "username"))
    Page<SnsAdvertVO> advertPage(Page<SnsAdvertVO> page, @Param("request") SnsAdvertRequest request);
}
